﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TERP.WaterClient.Common;
using System.Data;
using CommonUtils;

namespace TERP.WaterClient.DbServices
{
    public class StockOutService : BaseService
    {

		public StockOutService()
            : base()
        {
        }

		public DataSet Its_StockOut_Get(
                        string strStockOutID,
						string strStockOutDateFrom,
                        string strStockOutDateTo,
                        string strUnit,
						string strStatus,
						string strCusID,
						string strCusName
            )
        {
			string strStockOutIDConditionList = "";
			string strStockOutDateConditionList = "";
			string strCusIDConditionList = "";
			string strStatusConditionList = "";
			string strUnitConditionList = "";
			string strCusNameConditionList = "";

			if (!StringUtils.IsEmpty(strStockOutID))
			{
				strStockOutIDConditionList = "=  " + strStockOutID;
			}
			if (!StringUtils.IsEmpty(strCusID))
			{
			    strCusIDConditionList = "=  " + strCusID;
			}
			if (!StringUtils.IsEmpty(strUnit))
			{
				strUnitConditionList = "=" + strUnit ;
			}
			if (!StringUtils.IsEmpty(strCusName))
			{
				strCusNameConditionList = "like %" + strCusName +"%";
			}
			

			string strTId = SystemGlobal.Instance.GetNextTid();
			//
			try
			{
			DataSet mdsFinal = new DataSet();
			mdsFinal  = _dbService.Its_StockOut_Get(
					  _strGwUserCode,
					  _strGwPassword,
					  strTId,
					  _strSessionId,
					  strStockOutIDConditionList
					  , strStockOutDateConditionList
					  , strUnitConditionList
					  , strCusIDConditionList
					  , strCusNameConditionList
					  , strStatusConditionList
			      );
			    mdsFinal = TERP.Utils.CUtils.MyDSDecode(mdsFinal);
			    if (CMyDataSet.HasError(mdsFinal))
			    {
			        throw GenServiceException(mdsFinal);
			    }
			return mdsFinal;
			}
			catch (Exception ex)
			{
			    throw ex;
			}
        }

		public DataSet Its_StockOut_Get_Rpt(
						string strStockOutID,
						string strStockOutDateFrom,
						string strStockOutDateTo,
						string strUnit,
						string strCusID,
						string strCusName
			)
		{
			string strStockOutIDConditionList = "";
			string strStockOutDateConditionList = "";
			string strCusIDConditionList = "";
			string strUnitConditionList = "";
			string strCusNameConditionList = "";

			if (!StringUtils.IsEmpty(strStockOutID))
			{
				strStockOutIDConditionList = "=  " + strStockOutID;
			}
			if (!StringUtils.IsEmpty(strCusID))
			{
				strCusIDConditionList = "=  " + strCusID;
			}
			if (!StringUtils.IsEmpty(strUnit))
			{
				strUnitConditionList = "=" + strUnit;
			}
			if (!StringUtils.IsEmpty(strCusName))
			{
				strCusNameConditionList = "like %" + strCusName + "%";
			}


			string strTId = SystemGlobal.Instance.GetNextTid();
			//
			try
			{
				DataSet mdsFinal = new DataSet();
				mdsFinal = _dbService.Its_StockOut_Get_Rpt(
						  _strGwUserCode,
						  _strGwPassword,
						  strTId,
						  _strSessionId,
						  strStockOutIDConditionList
						  , strStockOutDateConditionList
						  , strUnitConditionList
						  , strCusIDConditionList
						  , strCusNameConditionList
					  );
				mdsFinal = TERP.Utils.CUtils.MyDSDecode(mdsFinal);
				if (CMyDataSet.HasError(mdsFinal))
				{
					throw GenServiceException(mdsFinal);
				}
				return mdsFinal;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}

		public DataSet Its_StockOut_Create(
							string strStockOutCode
			 , string strStockOutDate
			 , string strNote
			 , string strQuantity
			 , string strPrice
			 , string strPriceCuocVo
			 , string strUnit
			 , string strNoVo
			 , string strCuocVo
			 , string strCusID
			 , string strStatus
			 , string strAmountPaid
			)
		{
			string strTId = SystemGlobal.Instance.GetNextTid();
			//
			try
			{
				DataSet mdsFinal = new DataSet();
				mdsFinal = _dbService.Its_StockOut_Create(
						  _strGwUserCode,
						  _strGwPassword,
						  strTId,
						  _strSessionId
						 ,  strStockOutCode
						 ,  strStockOutDate
						 ,  strNote
						 ,  strQuantity
						 ,  strPrice
						 ,  strPriceCuocVo
						 ,  strUnit
						 ,  strNoVo
						 ,  strCuocVo
						 ,  strCusID
						 ,  strStatus
						 ,  strAmountPaid
					  );
				mdsFinal = TERP.Utils.CUtils.MyDSDecode(mdsFinal);
				if (CMyDataSet.HasError(mdsFinal))
				{
					throw GenServiceException(mdsFinal);
				}
				return mdsFinal;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}

		public DataSet Its_StockOut_Update(
							string strStockOutID
							, string strStockOutCode
							 , string strStockOutDate
							 , string strNote
							 , string strQuantity
							 , string strPrice
							 , string strPriceCuocVo
							 , string strUnit
							 , string strNoVo
							 , string strCuocVo
							 , string strCusID
							 , string strStatus
							 , string strAmountPaid
			)
		{
			string strTId = SystemGlobal.Instance.GetNextTid();
			//
			try
			{
				DataSet mdsFinal = new DataSet();
				mdsFinal = _dbService.Its_StockOut_Update(
						  _strGwUserCode,
						  _strGwPassword,
						  strTId,
						  _strSessionId,
						  strStockOutID
						 , strStockOutCode
						 , strStockOutDate
						 , strNote
						 , strQuantity
						 , strPrice
						 , strPriceCuocVo
						 , strUnit
						 , strNoVo
						 , strCuocVo
						 , strCusID
						 , strStatus
						 , strAmountPaid
					  );
				mdsFinal = TERP.Utils.CUtils.MyDSDecode(mdsFinal);
				if (CMyDataSet.HasError(mdsFinal))
				{
					throw GenServiceException(mdsFinal);
				}
				return mdsFinal;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}


		public DataSet Its_StockOut_Delete(
						string strStockOutID
			)
		{
			string strTId = SystemGlobal.Instance.GetNextTid();
			//
			try
			{
				DataSet mdsFinal = new DataSet();
				mdsFinal = _dbService.Its_StockOut_Delete(
						  _strGwUserCode,
						  _strGwPassword,
						  strTId,
						  _strSessionId,
						  strStockOutID
					  );
				mdsFinal = TERP.Utils.CUtils.MyDSDecode(mdsFinal);
				if (CMyDataSet.HasError(mdsFinal))
				{
					throw GenServiceException(mdsFinal);
				}
				return mdsFinal;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
    }

}
